//
//  FollowViewController.swift
//  SwiftDemo
//
//  Created by 李国卿 on 2020/1/16.
//  Copyright © 2020 guoqing.li. All rights reserved.
//

import UIKit

private let kFollowHeaderViewH : CGFloat = 120.0

class FollowViewController: BaseAnchorViewController {
    
    fileprivate lazy var followViewModel : FollowViewModel = FollowViewModel()
    
    fileprivate lazy var followHeaderView : FollowHeaderView = {
        
        let followHeaderView = FollowHeaderView.followHeaderView();
        
        followHeaderView.frame = CGRect(x: 0, y: -kFollowHeaderViewH, width: kScreenW, height: kFollowHeaderViewH)
        
        return followHeaderView;
        
    }()
}

extension FollowViewController{
    override func setupUI() {
        self.title = "关注"
        self.view.backgroundColor = UIColor.white;
        collectionView.addSubview(followHeaderView);
        collectionView.contentInset = UIEdgeInsets(top: kFollowHeaderViewH, left: 0, bottom: 0, right: 0)
        super.setupUI()
    }
}
//MARK 请求数据
extension FollowViewController{
    override func loadData() {
        //1 给父类的viewModel赋值
        baseVM = followViewModel
        //2.请求数据
        followViewModel.loadFollowData {
            //1.刷新表格
            self.collectionView.reloadData()
            //2.数据请求完成
            self.loadDataFinished()
        }
    }
}
//MARK 重写父类方法
extension FollowViewController{
    
    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        // 1.获取headerView
        let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "kHeaderViewID", for: indexPath) as! CollectionHeaderView

        // 2.设置属性
        headerView.titleLabel.text = "推荐直播"
        headerView.iconImageView.image = UIImage(named:"Img_orange")
        headerView.moreBtn.isHidden = true
        return headerView
    }
}

